<template>
  <el-dialog :title="title" :visible.sync="showPdf" @close="cancel" append-to-body width="90%" style="margin-top: -40px">
    <iframe v-if="showPdf" ref="pdfCotainer" :src="pdfData" style="width: 100%; height: 90vh"></iframe>
  </el-dialog>

</template>

<script>
import pdf from 'vue-pdf'
import { getFjById } from '@/api/gd/fj'

export default {
  components: {
    pdf
  },
  props: {
    title: {
      type: String
    },
    showPdf: {
      type: Boolean
    },
    fjId: {
      type: String
    },
    fileType: {
      type: String
    }
  },
  data() {
    return {
      pdfData: null,
    };
  },
  async created() {
    await this.init();
  },
  methods: {
    async init() {
      await getFjById(this.fjId, 'arraybuffer').then(response => {
        const binaryData = [];
        binaryData.push(response);
        this.pdfData = window.URL.createObjectURL(new Blob(binaryData, {type: 'application/pdf'}));
      })

    },
    cancel() {
      this.$emit("cancel")
    }
  },
};
</script>
